package geppetto.phraseHMM.phraseExtraction.extractedphrase.data;

import geppetto.phraseHMM.lexicalWeighting.AbstractLexicalWeightingCalculator;
import geppetto.phraseHMM.phraseExtraction.extractedphrase.ExtractedPhrasePair;
import geppetto.phraseHMM.phraseExtraction.extractedphrase.ExtractedPhrasePairData;
import geppetto.phraseHMM.phraseExtraction.extractedphrase.ExtractedPhrasePairDataCalc;

public class LexicalWeightDataCalc implements ExtractedPhrasePairDataCalc{

	AbstractLexicalWeightingCalculator lexicalCalc;
	boolean reverse = false;
	
	public LexicalWeightDataCalc(AbstractLexicalWeightingCalculator lexicalCalculator) {
		super();
		this.lexicalCalc = lexicalCalculator;
	}

	public ExtractedPhrasePairData calcData(ExtractedPhrasePair epp) {
		if(reverse){
			double reverseData = lexicalCalc.getReverseLexicalWeight(epp.getSentenceNumber(), epp.getSourceSentence(), epp.getForeignSentence(), epp.getSourceStartPos(), epp.getSourceEndPos(), epp.getForeignStartPos(), epp.getForeignEndPos());
			return new LexicalWeightData(reverseData);
		}
		double data = lexicalCalc.getLexicalWeight(epp.getSentenceNumber(), epp.getSourceSentence(), epp.getForeignSentence(), epp.getSourceStartPos(), epp.getSourceEndPos(), epp.getForeignStartPos(), epp.getForeignEndPos());		
		return new LexicalWeightData(data);
	}

	public ExtractedPhrasePairData loadFromString(String s) {
		return LexicalWeightData.parseString(s);
	}

	public boolean isReverse() {
		return reverse;
	}

	public void setReverse(boolean reverse) {
		this.reverse = reverse;
	}

}
